package suites.logger {
	import org.flexunit.asserts.assertEquals;
	import org.splink.library.logging.ILogger;
	import org.splink.library.logging.ILoggerFactory;
	import org.splink.library.logging.LoggerFactory;
	import org.splink.library.logging.LoggerProvider;

	/**
	 * @author maxmc
	 */
	public class BasePackageTest {
		private static var _logs : Array;
		private static var _factory : ILoggerFactory;

		[BeforeClass]
		public static function beforeClass() : void {
			_factory = new LoggerFactory("test");
			_factory.addLogOutput(new TestOutput(_logs = new Array()));
			assertEquals("test", _factory.id);
			
			_factory.basePackage = "org.splink";

			LoggerProvider.addLoggerFactory(_factory);
		}
		
		[AfterClass]
		public static function afterClass() : void {
			LoggerProvider.removeLoggerFactory(_factory);
		}

		[Before]
		public function before() : void {
			_logs.splice(0, _logs.length);
		}

		private function getLogger() : ILogger {
			return LoggerProvider.getLogger("test", BasePackageTest);
		}

		[Test]
		public function testTrace() : void {
			getLogger().trace("trace");
			assertEquals(0, _logs.length);
		}

		[Test]
		public function testInfo() : void {
			getLogger().info("info");
			assertEquals(0, _logs.length);
		}

		[Test]
		public function testDebug() : void {
			getLogger().debug("debug");
			assertEquals(0, _logs.length);
		}

		[Test]
		public function testWarn() : void {
			getLogger().warn("warn");
			assertEquals(0, _logs.length);
		}

		[Test]
		public function testError() : void {
			getLogger().error("error");
			assertEquals(0, _logs.length);
		}

		[Test]
		public function testFatal() : void {
			getLogger().fatal("fatal");
			assertEquals(0, _logs.length);
		}
	}
}
import org.splink.library.logging.LogEvent;
import org.splink.library.logging.logoutput.ILogOutput;
import org.splink.library.logging.logoutput.IOutputFormatter;

internal class TestOutput implements ILogOutput {
	private var _formatter : IOutputFormatter;
	private var _logs : Array;

	public function TestOutput(logs : Array) {
		_logs = logs;
	}

	public function setOuputFormatter(formatter : IOutputFormatter) : void {
		_formatter = formatter;
	}

	public function getInitialized() : Boolean {
		return true;
	}

	public function log(event : LogEvent) : void {
		_logs.push(_formatter.format(event));
	}
}